package com.qunar.mina.app.config;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DirectoryConfig {
	private static final Logger logger = LoggerFactory.getLogger(DirectoryConfig.class);
	private static Directory fsAddressDirectory;
	private static Directory fsUserDirectory;
	private static Directory fsAuditorDirectory;
	private static Directory fsPicDirectory;
	
	private static String address;
	private static String user;
	private static String auditor;
	private static String pic;
	
	static {
		Properties props = new Properties();
		try {
			props.load(DirectoryConfig.class.getClassLoader().getResourceAsStream("com/qunar/mina/app/config/lucene.properties"));
			address = props.getProperty("address");
			user = props.getProperty("user");
			auditor = props.getProperty("auditor");
			pic = props.getProperty("pic");
			
			fsAddressDirectory = FSDirectory.open(new File(address));
			fsUserDirectory = FSDirectory.open(new File(user));
			fsAuditorDirectory = FSDirectory.open(new File(auditor));
			fsPicDirectory = FSDirectory.open(new File(pic));
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
			throw new RuntimeException(e);
		}

	}
	
	public static Directory getFsAddressDirectory() {
		return fsAddressDirectory;
	}
	
	public static Directory getFSUserDirectory() {
		return fsUserDirectory;
	}
	
	public static Directory getFSAuditorDirectory() {
		return fsAuditorDirectory;
	}
	
	public static Directory getFSPicDirectory() {
		return fsPicDirectory;
	}

}
